package com.geo.smallcredit.activity;



import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.TextView;

import com.geo.smallcredit.R;
import com.geo.smallcredit.fragment.Credit_descriptionFragment;
import com.geo.smallcredit.fragment.Jiaoyi_descriptionFragment;
import com.geo.smallcredit.fragment.Livyue_descriptionFragment;
import com.geo.smallcredit.fragment.Shejiao_descriptionFragment;
import com.geo.smallcredit.fragment.Shenfen_descriptionFragment;
import com.geo.smallcredit.MainApplication.MainApplication;
import com.geo.smallcredit.vo.Home_score_DetailVo;

public class DescriptionActivity extends FragmentActivity implements OnClickListener{
	
	private ViewPager vp;
	public static final int TAB_ONE=0,TAB_TWO=1,TAB_THREE=2,TAB_FOUR=3,TAB_FIRVE=4;
	private RadioButton one,two,three,four,firv;
	private TextView close_dialog;
	private Intent intent;
	private Home_score_DetailVo hd;
	private int position;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MainApplication.getInstance().addActivity(DescriptionActivity.this);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.description_activity);
		intent=getIntent();
		hd=(Home_score_DetailVo) intent.getSerializableExtra("hmdesc");
		position=intent.getIntExtra("position",0);
		initview();
		initclick();
		vpAdapter adapter=new vpAdapter(getSupportFragmentManager());
		vp.setAdapter(adapter);
		addListener();
	}
	public void initview(){
		vp=(ViewPager) findViewById(R.id.description_activity);
		one=(RadioButton) findViewById(R.id.description_activity_one);
		two=(RadioButton) findViewById(R.id.description_activity_two);
		three=(RadioButton) findViewById(R.id.description_activity_three);
		four=(RadioButton) findViewById(R.id.description_activity_four);
		firv=(RadioButton) findViewById(R.id.description_activity_firve);
		close_dialog=(TextView) findViewById(R.id.description_activity_close);
	}
	public void initclick(){
		close_dialog.setOnClickListener(this);
	}
	private void addListener() {
		vp.setOnPageChangeListener(new OnPageChangeListener() {
			@Override
			public void onPageSelected(int id) {
				switch (id) {
				case TAB_ONE:
					one.setChecked(true);
					break;
				case TAB_TWO:
					two.setChecked(true);
					break;
				case TAB_THREE:
					three.setChecked(true);
					break;
				case TAB_FOUR:
					four.setChecked(true);
					break;
				case TAB_FIRVE:
					firv.setChecked(true);
					break;
				}
			}
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}
			@Override
			public void onPageScrollStateChanged(int arg0) {
			}
		});
	}
	
	public class vpAdapter extends FragmentPagerAdapter{
		public static final int TAB_COUNT = 5;
		public vpAdapter(FragmentManager fm) {
			super(fm);
		}
		@Override
		public Fragment getItem(int arg0) {
			switch (arg0) {
			case DescriptionActivity.TAB_ONE:
				Credit_descriptionFragment credit=new Credit_descriptionFragment();
				Bundle bundle=new Bundle();
				bundle.putInt("position", position);
				bundle.putSerializable("mec", hd);
				credit.setArguments(bundle);
				return credit;
			case DescriptionActivity.TAB_TWO:
				Jiaoyi_descriptionFragment jiaoyi=new Jiaoyi_descriptionFragment();
				Bundle bundle2=new Bundle();
				bundle2.putInt("position", position);
				bundle2.putSerializable("mec", hd);
				jiaoyi.setArguments(bundle2);
				return jiaoyi;
			case DescriptionActivity.TAB_THREE:
				Shenfen_descriptionFragment shenfen=new Shenfen_descriptionFragment();
				Bundle bundle3=new Bundle();
				bundle3.putInt("position", position);
				bundle3.putSerializable("mec", hd);
				shenfen.setArguments(bundle3);
				return shenfen;
			case DescriptionActivity.TAB_FOUR:
				Livyue_descriptionFragment livyue=new Livyue_descriptionFragment();
				Bundle bundle4=new Bundle();
				bundle4.putInt("position", position);
				bundle4.putSerializable("mec", hd);
				livyue.setArguments(bundle4);
				return livyue;
			case DescriptionActivity.TAB_FIRVE:
				Shejiao_descriptionFragment shejiao=new Shejiao_descriptionFragment();
				Bundle bundle5=new Bundle();
				bundle5.putInt("position", position);
				bundle5.putSerializable("mec", hd);
				shejiao.setArguments(bundle5);
				return shejiao;
			}
			return null;
		}
		@Override
		public int getCount() {
			return TAB_COUNT;
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.description_activity_close:
			finish();
			break;

		default:
			break;
		}
	}
}
